package com.huaxin.hxcloud.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;

import com.huaxin.common.BaseActivity;
import com.huaxin.common.Constants;
import com.huaxin.common.Entity.FeedBack;
import com.huaxin.common.view.ImageGroupView;
import com.huaxin.hxcloud.R;

import butterknife.BindView;

import static com.huaxin.hxcloud.R.id.imgGroup;


/**
 * Created by Administrator on 2016/11/7.
 * 我的申报详情
 */

public class ReportDetailActivity extends BaseActivity {


    @BindView(R.id.tv_unread)
    TextView       mTvUnread;
    @BindView(R.id.toolbar)
    Toolbar        mToolbar;
    @BindView(imgGroup)
    ImageGroupView mImgGroup;
    @BindView(R.id.des_tv)
    TextView       mDesTv;
    @BindView(R.id.declare_name_tv)
    TextView       mDeclareNameTv;
    @BindView(R.id.declare_state_tv)
    TextView       mDeclareStateTv;
    @BindView(R.id.company_tv)
    TextView       mCompanyTv;
    @BindView(R.id.address_tv)
    TextView       mAddressTv;
    @BindView(R.id.declare_time_tv)
    TextView       mDeclareTimeTv;
    @BindView(R.id.declare_dispose_tv)
    TextView       mDeclareDisposeTv;
    //    @BindView(R.id.more)
    //    ImageView      more;
    //    @BindView(R.id.toolbar)
    //    Toolbar        toolbar;
    //    @BindView(R.id.type_name)
    //    TextView       typeName;
    //    @BindView(R.id.state)
    //    TextView       state;
    //    @BindView(R.id.station_name)
    //    TextView       stationName;
    //    @BindView(R.id.station_address)
    //    TextView       stationAddress;
    //    @BindView(R.id.imgGroup)
    //    ImageGroupView imgGroup;
    //    @BindView(R.id.description)
    //    TextView       description;
    //    @BindView(R.id.tv_user)
    //    TextView       tvUser;
    //    @BindView(R.id.tv_report_date)
    //    TextView       tvReportDate;
    private FeedBack feedBack;

    public static void start(FragmentActivity activity, FeedBack feedBack) {
        Intent intent = new Intent(activity, ReportDetailActivity.class);
        intent.putExtra(Constants.IK_FEED_BACK, feedBack);
        activity.startActivity(intent);
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        super.getBundleExtras(extras);
        if (extras.containsKey(Constants.IK_FEED_BACK)) {
            feedBack = extras.getParcelable(Constants.IK_FEED_BACK);
        } else {
            finish();
        }
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_report_detal_new;
    }

    @Override
    public void initView() {
        super.initView();
        setSupportActionBar(mToolbar);
        mToolbar.setTitle("申报详情");

        loadType(feedBack.getType());
        loadState(feedBack.getBackState());
        loadText(mCompanyTv, feedBack.getStationName());
        loadText("地址:", mAddressTv, feedBack.getAddress());
        loadText("描述:", mDesTv, feedBack.getDes());
        //申报时间
        loadText("申报时间:", mDeclareTimeTv, dateFormat(feedBack.getCreateDate(), "HH:mm yyyy/MM/dd"));
        //        loadText(tvUser, feedBack.getCreator());
        //TODO 少 处理时间 字段
        String[] imgs = feedBack.getImgNames();
        mImgGroup.setImageUrl(feedBack.getImgNames());
        //            imgGroup.setVisibility(View.VISIBLE);
        //        }else{
        //            imgGroup.setVisibility(View.GONE);
        //        }

    }

    /**
     * 申报状态
     *
     * @param backState
     */
    private void loadState(int backState) {
        switch (backState) {//当前状态:null未发布;0未处理;1处理中;2处理完毕
            case 0:
            case 1:
                mDeclareStateTv.setText("未处理");
                mDeclareStateTv.setBackgroundResource(R.drawable.bg_state_gray);
                mDeclareStateTv.setTextColor(ContextCompat.getColor(this, R.color.state_gray));
                break;
            case 2:
                mDeclareStateTv.setText("处理中");
                mDeclareStateTv.setBackgroundResource(R.drawable.bg_state_orange);
                mDeclareStateTv.setTextColor(ContextCompat.getColor(this, R.color.state_orange));
                break;
            case 3:
                mDeclareStateTv.setText("已处理");
                mDeclareStateTv.setTextColor(ContextCompat.getColor(this, R.color.state_green));
                mDeclareStateTv.setBackgroundResource(R.drawable.bg_state_green);
                break;
            default:
                break;
        }
    }

    private void loadType(int type) {
        switch (type) {//"厂站停电", "设备故障", "其他"
            case 0:
                mDeclareNameTv.setText("厂站停电");
                break;
            case 1:
                mDeclareNameTv.setText("设备故障");
                break;
            case 2:
                mDeclareNameTv.setText("其他");
                break;
            default:
                break;
        }
    }

}
